﻿#include "maintitle.h"

qmainTitle::qmainTitle(QWidget *parent) :
    QWidget(parent)
{
    lbProject = new QLabel(tr("Bee Project"),this);
    lbFilePath= new QLabel(tr(""),this);

    btnMin    = new qcontrolBaseButton(tr(":png/png/round_minus.png"),this);
    btnMin->setToolTip(tr("最小化"));
    connect(btnMin,SIGNAL(clicked()),this,SIGNAL(showMin()));

    btnMax    = new qcontrolBaseButton(tr(":png/png/round_plus.png"),this);
    btnMax->setToolTip(tr("最大化"));
    connect(btnMax,SIGNAL(clicked()),this,SIGNAL(showMax()));

    btnClose  = new qcontrolBaseButton(tr(":png/png/round_delete.png"),this);
    btnClose->setToolTip(tr("关闭"));
    connect(btnClose,SIGNAL(clicked()),qApp,SLOT(quit()));

    QHBoxLayout *layout = new QHBoxLayout();
    layout->addWidget(lbProject,0,Qt::AlignVCenter);
    layout->addWidget(lbFilePath,1,Qt::AlignVCenter);
    layout->addStretch();
    layout->addWidget(btnMin);
    layout->addWidget(btnMax);
    layout->addWidget(btnClose);
    layout->setSpacing(0);
    layout->setContentsMargins(0,0,0,0);

    setLayout(layout);
    setFixedHeight(24);
    //setWindowOpacity(0.7);
    isMove=false;
}
void qmainTitle::mousePressEvent(QMouseEvent *event)
{
    if((event->x()+170) >= this->width())
        return;
    pressedPoint = event->pos();
    isMove = true;
}
void qmainTitle::mouseMoveEvent(QMouseEvent *event)
{
    if( (event->buttons()&Qt::LeftButton) && isMove)
    {
        QWidget *parWidget=this->parentWidget();
        QPoint nowParPoint=parWidget->pos();
        nowParPoint.setX(nowParPoint.x()+event->x() - this->pressedPoint.x());
        nowParPoint.setY(nowParPoint.y()+event->y() - this->pressedPoint.y());
        parWidget->move(nowParPoint);
    }
}
void qmainTitle::mouseReleaseEvent(QMouseEvent *)
{
    if(this->isMove)
        this->isMove=false;
}
void qmainTitle::mouseDoubleClickEvent(QMouseEvent *event)
{
    if((event->x()+170) >= this->width())
        return;
    emit showMax();
}
